/**     
* @Title: FanoutProducer.java   
* @Package me.mq.exchange.producer   
* @Description: TODO
* @author weiwei 
* @date 2018年5月30日 上午10:54:30   
* @version V1.0     
*/
package me.mq.exchange.producer;

import me.mq.exchange.config.RabbitMQConfigWithFanoutExchange;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.hutool.core.lang.Console;

/**   
 * @ClassName: FanoutProducer
 * @Description: TODO 
 * @author weiwei
 * @date 2018年5月30日 上午10:54:30   
 *      
 */
@Profile("fanout")
@RestController
public class FanoutProducer {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/sendMessage")
    public Object sendMessage() {
        new Thread(() -> {
            int count = 2;
            for (int i = 0; i < count; i++) {
                String value = "apple " + i;
                Console.log("apple send message {}", value);
                rabbitTemplate.convertAndSend(RabbitMQConfigWithFanoutExchange.EXCHANGE_NAME, RabbitMQConfigWithFanoutExchange.ROUTING_KEY_APPLE, value);
            }

            for (int i = 0; i < count; i++) {
                String value = "banana " + i;
                Console.log("banana send message {}", value);
                rabbitTemplate.convertAndSend(RabbitMQConfigWithFanoutExchange.EXCHANGE_NAME, RabbitMQConfigWithFanoutExchange.ROUTING_KEY_BANANA, value);
            }
            
            for (int i = 0; i < count; i++) {
                String value = "orange " + i;
                Console.log("orange send message {}", value);
                rabbitTemplate.convertAndSend(RabbitMQConfigWithFanoutExchange.EXCHANGE_NAME, RabbitMQConfigWithFanoutExchange.ROUTING_KEY_ORANGE, value);
            }
        }).start();
        return "ok";
    }

}
